home *** CD-ROM | disk | FTP | other *** search
- #include "MPDialogs.h"
- #include "SampleProcs.h"
-
- /* Sample Edit Action Procedure
- * mType : message type
- * hPtr : storage for data representing control
- * iHandle : handle if control item
- * pane : pane where the control resides
- * item : item number of control in the pane
- */
- short MyEditAction(short mType, char *hPtr, Handle iHandle, short pane, short item)
- {
- short ret = 0;
- long val;
- Str255 textStr;
-
- switch (mType) {
- case kP2TAction: // Store value of control in memory
- GetDialogItemText((Handle) iHandle, textStr);
- StringToNum(textStr, &val);
- *(long *) hPtr = val;
- ret = sizeof(long);
- break;
- case kT2PAction: // Set value of control based on memory
- val = *(long *) hPtr;
- NumToString(val, textStr);
- SetDialogItemText((Handle) iHandle, textStr);
- ret = sizeof(long);
- break;
- case kCalcAction: // Return length of storage required
- ret = sizeof(long);
- break;
- case kInitAction: // Initialize value
- *(long *) hPtr = 0;
- ret = sizeof(long);
- break;
- default:
- break;
- }
-
- // Return length of storage used/required (must be the same in each case).
- return ret;
- }
-
- /* Sample Click Action Procedure
- * mType : message type
- * dlog : dialog where control is installed
- * pane : pane where the control resides
- * item : item number of control in the pane
- */
- short MyClickAction(short mType, DialogPtr dlog, short pane, short item)
- {
- MPDHdl dataH;
- short iType, val = 0;
- Rect iRect;
- Handle iHandle;
- Str255 theStr;
-
- // Obtain multi-pane dialog state record
- dataH = (MPDHdl) GetWRefCon(dlog);
-
- // Handle the second item validation.
- if (mType == kValidateAction) {
- // Validation fails if non-digits are in the field
- if (pane == kCommPane && item == kFrequency + (*dataH)->baseItems) {
- GetDialogItem(dlog, item, &iType, &iHandle, &iRect);
- GetDialogItemText(iHandle, theStr);
- val = VerifyDigits(theStr);
- if (val) StopAlert(ALERT_Invalid, NULL);
- }
- // All other items validate a-okay
- return val;
- }
-
- // Only interested in the third checkbox now,
- // so handle things the default way
- if (pane != kMiscellaneousPane || item != kEnableSelfDestruct + (*dataH)->baseItems)
- return (DefaultClickAction(mType, dlog, pane, item));
-
- // Initialize and Click messages are almost handled the same
-
- // Dim the third checkbox based on the value of the second
- GetDialogItem(dlog, item, &iType, &iHandle, &iRect);
- val = GetControlValue((ControlHandle)iHandle);
- switch (mType) {
- // Toggle the item in response to the user click
- case kClickAction:
- val = !val;
- SetControlValue((ControlHandle) iHandle, val);
- // Fall through!
- // In either case, enable/disable next check box
- case kInitAction:
- AbleDItem(dlog, kSelfDestruct + (*dataH)->baseItems, val);
- break;
- }
-
- // Initialize and Click messages should never fail
- return 0;
- }
-
- /* Ensure the passed pascal string contains only digits.
- */
- short VerifyDigits(StringPtr inString)
- {
- int i;
-
- for(i=1; i<=*inString; i++) {
- if (inString[i] < '0' || inString[i] > '9') return 1;
- }
- return 0;
- }
-